import axios from 'axios'
import { Loading } from 'element-ui';
let loading;
export default{
  install(Vue){
    // 请求拦截器
    axios.interceptors.request.use( (config)=>{
      // 打开loading加载
      loading = Loading.service({
        fullscreen:true,
        text:'加载中...',
        background:"rgba(0,0,0,.7)",
      })
      var token=localStorage.getItem('token')
      config.headers.Authorization=token
      return config
    },function(error){
      return Promise.reject(error)
    })
    // 响应拦截器
    axios.interceptors.response.use((response)=>{
      // 关闭loading加载
      loading.close();
      return response
    },function(error){
      return Promise.reject(error)
    })

    Vue.prototype.$http=async function({url,method,data}){
      return axios({
        url,
        method,
        data
      })
    }
  }
}